package command;

import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import base.*;


public class UpdateCommand extends Command{

	InetAddress ip;
	private int port;
	
	private String sresponse;
	
	private List<String> keySeeder;
	private List<String> keyLeecher;
	
	
	public UpdateCommand (){
		this.keySeeder = new ArrayList<String>();
		this.keyLeecher = new ArrayList<String>();
	}
	
	public boolean run(){
		DataTracker d = new DataTracker();
		d.createEm();
		Peer p = d.findPeer(this.ip);
		for(String s: keySeeder){			
			d.checkUpdate(p, s, Share.Stat.SEEDER);
		}
		for(String s: keyLeecher){
			d.checkUpdate(p, s, Share.Stat.LEECHER);			
		}
		d.closeEm();
		sresponse = "ok";
		return true;
	}
	
	public void addSeedKey(String key){
		keySeeder.add(key);
	}
	
	public void addLeechKey(String key){
        keyLeecher.add(key);
	}
		
	public InetAddress getIp() {
		return ip;
	}
	public void setIp(InetAddress ip) {
		this.ip = ip;
	}
	public int getPort() {
		return port;
	}
	public void setPort(int port) {
		this.port = port;
	}
	public String getSresponse() {
		return sresponse;
	}
	public void setSresponse(String sresponse) {
		this.sresponse = sresponse;
	}
	
}
